#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#define BUFSIZE 1024

int main(int argc, char *argv[]) 
{
	if (argc < 3) {
		fprintf(stderr, "Usage:...\n");
		exit(1);
	}

	int fd1, fd2;

	if ((fd1 = open(argv[1], O_RDONLY)) < 0) {
		perror("fopen:");
		exit(1);
	}

	if ((fd2 = open(argv[2], O_CREAT | O_WRONLY | O_TRUNC, 0600)) < 0) {
                perror("fopen:");
		exit(1);
        }

	char buf[BUFSIZE];
	int n;

	while ((n = read(fd1, buf, BUFSIZE)) > 0) {
		if (write(fd2, buf, n) != n) {
			perror("write:");
			break;
		}
	}

	close(fd1);
	close(fd2);
	exit(0);
}
